package com.service.atf.base.model;

import com.service.atf.base.exception.TFException;
import com.service.atf.base.utils.ATFConstants;
import com.service.atf.base.utils.ATFLogger;
import com.luotao.devp.base.utils.ByteUtil;
import com.luotao.devp.base.utils.MD5Util;

import java.util.UUID;

/**
 * User: luotao
 * Date: 12-2-25
 * Time: 18:09
 * �û�����	�ַ�char(32)	ʡ����+�б���+SEQ
 * TOKEN	�ַ�char(32)
 * �˻����	long
 * ��ֵ������	long
 * ���𶳽���	long
 * �������	long
 * ��ʱ�������	Long
 * ���ճ�ֵ�ܴ���	Byte
 * ���ճ�ֵ�ܽ��	int
 * ���������ܴ���	Byte
 * ���������ܽ��	int
 * ��������ܴ���	Byte
 * ��������ܽ��	int
 * ������Ϸ�ۻ�ʱ��	int	��
 * ���ף�Ͷע����ˮ��	Char(30)	�ļ�INDEX+record  INDEX
 */
public class Account {
    public void clear() {
        customerCode = "";
        token = "";
        balcCharge = 0;
        balcAward = 0;
        frezCharge = 0;
        frezAward = 0;
        tmpAward = 0;
        remainCountCharge = 0;
        remainCountCash = 0;
        remainCountSale = 0;
        remainCharge = 0;
        remainCash = 0;
        remainSale = 0;
        remainGameTime = 0;
        lastFlowId = "";
        startTime = 0;
        maxCharge = 0;
        minDraw = 0;
        maxDraw = 0;
        maxConsume = 0;
        md5Bingo = "";
        everyDayChargeCount = 0;
        everyDayCashCount = 0; //
        everyDaySaleCount = 0; //
        everyDayChargeAmount = 0;
        everyDayCashAmount = 0; //
        everyDaySaleAmount = 0; //
        everyDayGameTime = 0; //	NU
        concurrLock = 0;
    }

    public static final String AC_FILE_PREFIX = "A";

    public static final String AC_FILE_SUFFIX = ".AC";

    private String customerCode;

    private String token;

    private long balcCharge;

    private long balcAward;

    private long frezCharge;

    private long frezAward;

    private long tmpAward;

    private short remainCountCharge;

    private short remainCountCash;

    private short remainCountSale;

    private long remainCharge;

    private long remainCash;

    private long remainSale;

    private long remainGameTime;

    private String lastFlowId = "";

    private int startTime;

    private long maxCharge;

    private long minDraw;

    private long maxDraw;

    private long maxConsume;

    private String md5Bingo;

    private short everyDayChargeCount; //	NUMBER(4)	N			�����˻�ÿ�ճ�ֵ�޴�
    private short everyDayCashCount; //	NUMBER(4)	N			�����˻�ÿ�������޴�
    private short everyDaySaleCount; //	NUMBER(4)	N			�����˻�ÿ������޴�

    private long everyDayChargeAmount; //	NUMBER(16)	N			�����˻�ÿ�ճ�ֵ�޶�
    private long everyDayCashAmount; //	NUMBER(16)	N			�����˻�ÿ�������޶�
    private long everyDaySaleAmount; //	NUMBER(16)	N			�����˻�ÿ������޶�
    private long everyDayGameTime; //	NUMBER(8)	N			�����˻�ÿ����Ϸʱ�䣨��λ���룩

    private int lastActiveTime;  //���ʱ��

    private byte concurrLock;

    public int getLastActiveTime() {
        return lastActiveTime;
    }

    public void setLastActiveTime(int lastActiveTime) {
        this.lastActiveTime = lastActiveTime;
    }

    public short getEveryDayChargeCount() {
        return everyDayChargeCount;
    }

    public void setEveryDayChargeCount(short everyDayChargeCount) {
        this.everyDayChargeCount = everyDayChargeCount;
    }

    public short getEveryDayCashCount() {
        return everyDayCashCount;
    }

    public void setEveryDayCashCount(short everyDayCashCount) {
        this.everyDayCashCount = everyDayCashCount;
    }

    public short getEveryDaySaleCount() {
        return everyDaySaleCount;
    }

    public void setEveryDaySaleCount(short everyDaySaleCount) {
        this.everyDaySaleCount = everyDaySaleCount;
    }

    public long getEveryDayChargeAmount() {
        return everyDayChargeAmount;
    }

    public void setEveryDayChargeAmount(long everyDayChargeAmount) {
        this.everyDayChargeAmount = everyDayChargeAmount;
    }

    public long getEveryDayCashAmount() {
        return everyDayCashAmount;
    }

    public void setEveryDayCashAmount(long everyDayCashAmount) {
        this.everyDayCashAmount = everyDayCashAmount;
    }

    public long getEveryDaySaleAmount() {
        return everyDaySaleAmount;
    }

    public void setEveryDaySaleAmount(long everyDaySaleAmount) {
        this.everyDaySaleAmount = everyDaySaleAmount;
    }

    public long getEveryDayGameTime() {
        return everyDayGameTime;
    }

    public void setEveryDayGameTime(long everyDayGameTime) {
        this.everyDayGameTime = everyDayGameTime;
    }


    public void setMd5Bingo(String flowId, int awardMoney) {
        setMd5Bingo(MD5Util.MD5Encode(flowId + awardMoney));
    }

    public long getMaxConsume() {
        return maxConsume;
    }

    public void setMaxConsume(long maxConsume) {
        this.maxConsume = maxConsume;
    }

    public long getMaxCharge() {
        return maxCharge;
    }

    public void setMaxCharge(long maxCharge) {
        this.maxCharge = maxCharge;
    }

    public long getMinDraw() {
        return minDraw;
    }

    public void setMinDraw(long minDraw) {
        this.minDraw = minDraw;
    }

    public long getMaxDraw() {
        return maxDraw;
    }

    public void setMaxDraw(long maxDraw) {
        this.maxDraw = maxDraw;
    }

    public void setBalcAward(long balcAward) {
        this.balcAward = balcAward;
    }

    public Account byte2Object(byte[] data) {
        try {
            customerCode = ByteUtil.readString(data, 0, 20);
            token = ByteUtil.readString(data, 20, 32);
            balcCharge = ByteUtil.readLong(data, 52);
            balcAward = ByteUtil.readLong(data, 60);
            frezCharge = ByteUtil.readLong(data, 68);
            frezAward = ByteUtil.readLong(data, 76);
            tmpAward = ByteUtil.readLong(data, 84);
            remainCountSale = (short) ByteUtil.readShort(data, 92);
            remainCountCharge = (short) ByteUtil.readShort(data, 94);
            remainCountCash = (short) ByteUtil.readShort(data, 96);
            remainSale = ByteUtil.readLong(data, 98);
            remainCharge = ByteUtil.readLong(data, 106);
            remainCash = ByteUtil.readLong(data, 114);
            remainGameTime = ByteUtil.readLong(data, 122);
            lastFlowId = ByteUtil.readString(data, 130, 24);
            startTime = ByteUtil.readInt(data, 154);
            maxConsume = ByteUtil.readLong(data, 158);
            maxCharge = ByteUtil.readLong(data, 166);
            minDraw = ByteUtil.readLong(data, 174);
            maxDraw = ByteUtil.readLong(data, 182);
            md5Bingo = ByteUtil.readString(data, 190, 32);

            everyDayChargeCount = (short) ByteUtil.readShort(data, 222);
            everyDayCashCount = (short) ByteUtil.readShort(data, 224);
            everyDaySaleCount = (short) ByteUtil.readShort(data, 226);

            everyDayChargeAmount = ByteUtil.readLong(data, 228);
            everyDayCashAmount = ByteUtil.readLong(data, 236);
            everyDaySaleAmount = ByteUtil.readLong(data, 244);
            everyDayGameTime = ByteUtil.readLong(data, 252);

            lastActiveTime = ByteUtil.readInt(data, 260);

            concurrLock = (byte) ByteUtil.read(data, 264);
            return this;
        } catch (Exception e) {
            e.printStackTrace();
            String str = "���byte����ac���˻���Ϣʱ�������";
            ATFLogger.syserr(str);
            throw new TFException(ATFConstants.ATF_AC_BYTE_CONV_ERR, str);
        }
    }

    public byte[] object2Byte() {
        try {
            byte[] result = new byte[265];
            ByteUtil.writeString(result, 0, getCustomerCode(), 20);
            ByteUtil.writeString(result, 20, getToken(), 32);
            ByteUtil.writeLong(result, 52, getBalcCharge());
            ByteUtil.writeLong(result, 60, getBalcAward());
            ByteUtil.writeLong(result, 68, getFrezCharge());
            ByteUtil.writeLong(result, 76, getFrezAward());
            ByteUtil.writeLong(result, 84, getTmpAward());
            ByteUtil.writeShort(result, 92, getRemainCountSale());
            ByteUtil.writeShort(result, 94, getRemainCountCharge());
            ByteUtil.writeShort(result, 96, getRemainCountCash());
            ByteUtil.writeLong(result, 98, getRemainSale());
            ByteUtil.writeLong(result, 106, getRemainCharge());
            ByteUtil.writeLong(result, 114, getRemainCash());
            ByteUtil.writeLong(result, 122, getRemainGameTime());
            ByteUtil.writeString(result, 130, getLastFlowId(), 24);
            ByteUtil.writeInt(result, 154, getStartTime());
            ByteUtil.writeLong(result, 158, getMaxConsume());
            ByteUtil.writeLong(result, 166, getMaxCharge());
            ByteUtil.writeLong(result, 174, getMinDraw());
            ByteUtil.writeLong(result, 182, getMaxDraw());
            ByteUtil.writeString(result, 190, getMd5Bingo(), 32);

            ByteUtil.writeShort(result, 222, everyDayChargeCount);
            ByteUtil.writeShort(result, 224, everyDayCashCount);
            ByteUtil.writeShort(result, 226, everyDaySaleCount);

            ByteUtil.writeLong(result, 228, everyDayChargeAmount);
            ByteUtil.writeLong(result, 236, everyDayCashAmount);
            ByteUtil.writeLong(result, 244, everyDaySaleAmount);
            ByteUtil.writeLong(result, 252, everyDayGameTime);
            ByteUtil.writeInt(result, 260, lastActiveTime);
            ByteUtil.write(result, 264, getConcurrLock());
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            String str = "���byte����ac���˻���Ϣʱ�������";
            ATFLogger.syserr(str);
            throw new TFException(ATFConstants.ATF_AC_BYTE_CONV_ERR, str);
        }
    }

    public String getMd5Bingo() {
        return md5Bingo;
    }

    public void setMd5Bingo(String md5Bingo) {
        this.md5Bingo = md5Bingo;
    }

    public byte getConcurrLock() {
        return concurrLock;
    }

    public void setConcurrLock(byte concurrLock) {
        this.concurrLock = concurrLock;
    }

    public String getCustomerCode() {
        return customerCode;
    }

    public void setCustomerCode(String customerCode) {
        this.customerCode = customerCode;
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public long getBalcCharge() {
        return balcCharge;
    }

    public void setBalcCharge(long balcCharge) {
        this.balcCharge = balcCharge;
    }

    public long getBalcAward() {
        return balcAward;
    }

    public long getFrezCharge() {
        return frezCharge;
    }

    public void setFrezCharge(long frezCharge) {
        this.frezCharge = frezCharge;
    }

    public long getFrezAward() {
        return frezAward;
    }

    public void setFrezAward(long frezAward) {
        this.frezAward = frezAward;
    }

    public long getTmpAward() {
        return tmpAward;
    }

    public void setTmpAward(long tmpAward) {
        this.tmpAward = tmpAward;
    }

    public short getRemainCountSale() {
        return remainCountSale;
    }

    public void setRemainCountSale(short remainCountSale) {
        this.remainCountSale = remainCountSale;
    }

    public short getRemainCountCharge() {
        return remainCountCharge;
    }

    public void setRemainCountCharge(short remainCountCharge) {
        this.remainCountCharge = remainCountCharge;
    }

    public short getRemainCountCash() {
        return remainCountCash;
    }

    public void setRemainCountCash(short remainCountCash) {
        this.remainCountCash = remainCountCash;
    }

    public long getRemainSale() {
        return remainSale;
    }

    public void setRemainSale(long remainSale) {
        this.remainSale = remainSale;
    }

    public long getRemainCharge() {
        return remainCharge;
    }

    public void setRemainCharge(long remainCharge) {
        this.remainCharge = remainCharge;
    }

    public long getRemainCash() {
        return remainCash;
    }

    public void setRemainCash(long remainCash) {
        this.remainCash = remainCash;
    }


    public long getRemainGameTime() {
        return remainGameTime;
    }

    public void setRemainGameTime(long remainGameTime) {
        this.remainGameTime = remainGameTime;
    }

    public String getLastFlowId() {
        return lastFlowId;
    }

    public void setLastFlowId(String lastFlowId) {
        this.lastFlowId = lastFlowId;
    }

    public int getStartTime() {
        return startTime;
    }

    public void setStartTime(int startTime) {
        this.startTime = startTime;
    }

    public static String createACFileName() {
        StringBuffer str = new StringBuffer();
        str.append(AC_FILE_PREFIX).append("");


        String uuid = UUID.randomUUID().toString().replace("-", "");
        str.append(uuid).append(AC_FILE_SUFFIX);
        return str.toString();
    }

    public void addBalanceAward() {
        this.balcAward += tmpAward;
    }

    public short getTotalCountCharge() {
        return (short) (everyDayChargeCount - remainCountCharge);
    }

    public short getTotalCountCash() {
        return (short) (everyDayCashCount - remainCountCash);
    }

    public long getTotalCharge() {
        return everyDayChargeAmount - remainCharge;
    }

    public short getTotalCountSale() {
        return (short) (everyDaySaleCount - remainCountSale);
    }

    public long getTotalCash() {
        return everyDayCashAmount - remainCash;
    }


    public long getTotalSale() {
        return everyDaySaleAmount - remainSale;
    }

    public long getTotalGameTime() {
        return everyDayGameTime - remainGameTime;
    }


    public static void main(String[] args) throws Exception {
        Account bussAccount = new Account();
        bussAccount.setCustomerCode("01234567890123456789");
        bussAccount.setToken(UUID.randomUUID().toString().replace("-", ""));
        byte[] bb = bussAccount.object2Byte();
        System.out.println("bb.length = " + bb.length);
    }
}